package com.nomito.minimito.controller.front;

import com.nomito.minimito.common.utils.R;
import com.nomito.minimito.entity.SqTopicCommentEntity;
import com.nomito.minimito.entity.SqTopicEntity;
import com.nomito.minimito.service.SqTopicCommentService;
import com.nomito.minimito.service.SqTopicService;
import com.nomito.minimito.vo.CreateActivityVo;
import com.nomito.minimito.vo.TopicCommentVo;
import com.nomito.minimito.vo.TopicVo;
import com.nomito.minimito.vo.UserTopicVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@Api(tags = "动态接口")
@RestController
@CrossOrigin
@RequestMapping("/front/topic")
public class FTopicController {

    @Autowired
    SqTopicService sqTopicService ;

    @Autowired
    SqTopicCommentService sqTopicCommentService;

    /**
     *
     * @param  key 排序关键字 0-最早 1-最晚 2-最热
     * @return R
     *
     */
    @ApiOperation(value = "获取匿名动态列表接口")
    @GetMapping("/getTopicList")
    public R getTopicList(@RequestParam Integer key ){
       List<SqTopicEntity> topicList=sqTopicService.getTopicList(key);
       return R.ok("操作成功！").put("data",topicList);
    }

    /**
     *
     * @param  topicId
     * @return R
     *
     */
    @ApiOperation(value = "获取动态评论列表接口")
    @GetMapping("/getTopicCommentList")
    public R getTopicCommentList(@RequestParam Long topicId ){
        List<SqTopicCommentEntity> sqTopicCommentEntityList=sqTopicCommentService.getTopicCommentList(topicId);
        return R.ok("操作成功！").put("data",sqTopicCommentEntityList);
    }

    /**
     *
     * @param  topicCommentVo
     * @return R
     *
     */
    @ApiOperation(value = "添加动态评论接口")
    @PostMapping("/insertTopicComment")
    public R insertTopicComment(@RequestBody TopicCommentVo topicCommentVo){
         sqTopicCommentService.insertTopicComment(topicCommentVo);
        return R.ok();
    }

    /**
     *
     * @param  topicVo
     * @return R
     *
     */
    @ApiOperation(value = "发布动态接口")
    @PostMapping("/insertTopicDetail")
    public R insertTopicComment(@RequestBody TopicVo topicVo){
        sqTopicService.insertTopicDetail(topicVo);
        return R.ok();
    }

    /**
     *
     * @param  topicVo
     * @return R
     *
     */
    @ApiOperation(value = "查询动态接口")
    @PostMapping("/checkUserTopicDetail")
    public R insertTopicComment(@RequestParam Long userId){
        UserTopicVo userTopicVo = sqTopicService.getUserTopicList(userId);
        return R.ok().put("data",userTopicVo);
    }


}
